package com.example.readroomforpaging3.room

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.example.readroomforpaging3.model.Article

@Database(entities = [Article::class, RemoteKeys::class], version = 1, exportSchema = false)
abstract class ArticleDatabase: RoomDatabase() {

    abstract fun articleDao(): ArticleDao
    abstract fun getRepoDao(): RemoteKeysDao

    companion object {
        private var INSTANCE: ArticleDatabase? = null

        fun getDatabase(context: Context): ArticleDatabase {
           return INSTANCE ?: synchronized(this) {
               val instance = Room.databaseBuilder(context, ArticleDatabase::class.java, "article_database").build()
               INSTANCE = instance
               instance
           }
        }
    }
}